package main

import (
	"Ghost/cmd"
	"Ghost/mss"
	"Ghosted/util"
	"errors"
	"strconv"
)

var theMSCmd cmd.ICommandEer

func init() { theMSCmd = mss.Regist(SID_CMD_CONSOLE, &ConsoleInput{}).(*ConsoleInput) }

type ConsoleInput struct {
	util.ConsoleLine
}

func (this *ConsoleInput) HandleInit(own mss.IOServicer) {
	this.ConsoleLine.HandleInit(own)

	this.RegistHandle("SetLoginHost", "Set login host [Host1...].",
		this.OnCommandSetLoginHost)
	this.RegistHandle("CreateRobot", "Create Robot Client [num].",
		this.OnCommandCreateRobot)
	this.RegistHandle("DestroyRobot", "Destroy Robot Client [id].",
		this.OnCommandDestroyRobot)
}
func (this *ConsoleInput) OnCommandSetLoginHost(params ...string) (string, error) {
	if len(params) == 0 {
		return "", errors.New("params need some string value of host.")
	}
	LoginHost = params
	return "", nil
}
func (this *ConsoleInput) OnCommandCreateRobot(params ...string) (string, error) {
	if len(params) == 0 {
		return "", errors.New("params need a int value of robot num.")
	}
	count, err := strconv.ParseInt(params[0], 10, 32)
	if err != nil {
		return "", errors.New("params[1] need a int number.")
	}
	theMCMain.CreateRobot(int(count))
	return "", nil
}
func (this *ConsoleInput) OnCommandDestroyRobot(params ...string) (string, error) {
	if len(params) == 0 {
		return "", errors.New("params need a int value of robot num.")
	}
	robotId, err := strconv.ParseInt(params[0], 10, 32)
	if err != nil {
		return "", errors.New("params[1] need a int number.")
	}
	theMCMain.DestryRobot(int(robotId))
	return "", nil
}
